var FileChose = React.createClass({
    getInitialState:function(){
        return {
            file:''
        }
    },
    // 暴露出去给父组件的方法
    getFile:function(){
        var _tmp = this.state.file;
        return _tmp;
    },
    change:function(e){
        // console.log(e.target.file)
        var files = e.target.files;
        var url = window.URL || window.webkitURL;
        var imageBlobUrl = url.createObjectURL(files[0]);
        this.setState({
            imgsrc: imageBlobUrl,
            file:files[0],
        });
        this.refs.img.onload = function(){
            url.revokeObjectURL(imageBlobUrl);
        }
    },
    choseFile:function(){
        this.refs.iptfile.click();
    },
    clean:function(){
        this.setState({
            imgsrc:'',
            file:''
        })
    },
    render:function(){
        return (
            <div>
                <img className="add-img" ref="img" src={this.state.imgsrc} onClick={this.choseFile}/>
                <input ref="iptfile" type="file" className="f-dn" onChange={this.change} />
            </div>
        )
    }
});
module.exports = FileChose;
